<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        ul{
            list-style: none;
            background-color: #aaa;
            width: 100px;
            height: 300px;
            margin: 100px 400px;
            position: relative;
        }
        ul li{
            width: 100px;
        }
        ul li p{
            width: 100px;
            height: 30px;
            text-align: center;
            line-height: 30px;
        }
        ul li p.active{
            background-color: aqua;
            border: 2px solid orange;
            border-right: none;
            position: relative;
            left: 1px;
            z-index: 10;
        }
        ul li div{
            width: 300px;
            height: 300px;
            background-color: aqua;
            position: absolute;
            right: -300px;
            top: 0;
            display: none;
            text-align: center;
        }
        ul li div.on{
            display: block;
            border: 1px solid orange;
        }
    </style>
</head>
<body>
    <ul>
        <li>
            <p>菜单一</p>
            <div>
                商品一
            </div>
        </li>
        <li>
            <p>菜单二</p>
            <div>
                商品二
            </div>
        </li>
        <li>
            <p>菜单三</p>
            <div>
                商品三
            </div>
        </li>
        <li>
            <p>菜单四</p>
            <div>
                商品四
            </div>
        </li>
    </ul>
    <script>
        //需求：鼠标移入对应菜单栏时候出现对应商品栏
        let lis=document.querySelectorAll("ul li")
        let ps=document.querySelectorAll("ul li p")
        let divs=document.querySelectorAll("ul li div")
        lis.forEach((i,j) => {
            i.addEventListener("mouseenter",function(){
                ps[j].classList.add("active")
                divs[j].classList.add("on")
            })
            i.addEventListener("mouseleave",function(){
                ps[j].classList.remove("active")
                divs[j].classList.remove("on")
            })
        });
    </script>
</body>
</html>